#ifndef YEP_UI_WINDOW_HPP
#define YEP_UI_WINDOW_HPP

#include "Widget.hpp"
#include <vector>
#include <algorithm>

namespace yep
{
    using namespace std;
    /**
     * @brief A simple window.
     *
     * It resizes the inner component to fit within its limits. A compont should be included only
     *  once, because two or more can lead to strange errors. So it's possible, but not currently supported.
     **/
    class Window: public Widget
    {
    public:

        /**
         * @brief Constructor
         **/
        Window()
        {
            _transparent = false;
            Uint8 left, top, right, bottom;
            style->windowBorders(left, top, right, bottom);
            setLeftBorder(left);
            setTopBorder(top);
            setRightBorder(right);
            setBottomBorder(bottom);
        }

//        /**
//         * @brief Draw the window and its subwidgets
//         **/
//        void evDraw(SDL_Surface *screen)
//        {
//            _style->drawWindow(screen, _title, focused(), transparent(), absolutePosition(), absoluteArea(), textColor(), backgroundColor() );
//            for(auto widget = _children.begin(); widget != _children.end(); ++widget)
//            {
//                (*widget)->evDraw(screen);
//            }
//        }

        /**
         * @brief Returns whether it is transparent
         **/
        bool transparent() const
        {
            return _transparent;
        }

        /**
         * @brief Turns on or off the transparent.
         **/
        void transparent(bool value)
        {
            _transparent = value;
        }

        /**
         * @brief Returns the title
         **/
        const string &title()
        {
            return _title;
        }

        /**
         * @brief Changes the title
         **/
        void title(const string &value)
        {
            _title = value;
        }

        /**
         * @brief Adds a widget to the window.
         **/
        void insert(Widget &widget)
        {
            _children.push_back(&widget);
            widget.setParent(this);
        }

        /**
         * @brief remove a widget from the window.
         **/
        void erase(Widget &widget)
        {
            _children.erase(find(_children.begin(), _children.end(), &widget));
        }

        /**
         * @brief remove all widgets from the window.
         **/
        void clear()
        {
            _children.clear();
        }

        /**
         * @brief Returns the occurences of widget.
         *
         * The value should be 0 or 1. If the returned value is bigger
         *  than it, there is a problem of duplicate widgets, witch can
         *  lead to severe errors.
         **/
        size_t count(Widget &widget)
        {
            return std::count(_children.begin(), _children.end(), &widget);
        }
    private:
        bool _transparent;
        string _title;
        vector<Widget*> _children;
    };
}

#endif // YEP_UI_WINDOW_HPP

